package com.tangqiao;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.MouseEvent;

public class Clicker {
	private Point base;
	private Robot robot;
	public Clicker(Point base) {
		this.base = base;
		try {
			robot = new Robot();
		} catch (AWTException e) {
			e.printStackTrace();
		}
	}
	
	public Clicker(int x, int y) {
		this(new Point(x, y));
	}
	
	public void click(Point p) {
		if (p == null) return ;
		try {
			Thread.sleep(50);
			robot.mouseMove(base.x + p.x , base.y + p.y);
			Thread.sleep(50);
			robot.mousePress(MouseEvent.BUTTON1_MASK);
			Thread.sleep(50);
			robot.mouseRelease(MouseEvent.BUTTON1_MASK);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
